/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.crud.Impl;

import com.startup.musicstore.model.Contact;
import com.startup.musicstore.model.Customer;
import com.startup.musicstore.model.CustomerAddress;
import com.startup.musicstore.services.crud.ContactsService;
import com.startup.musicstore.services.crud.CustomerCrudService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author given
 */
public class ContactsServiceImpl implements ContactsService{
    private static ApplicationContext ctx;
    
    @Override
    public String getStreetAddress(Long aLong) {
        ctx = new ClassPathXmlApplicationContext("classpath:com/startup/musicstore/app/conf/applicationContext-*.xml");
        CustomerCrudService customerCrudService = (CustomerCrudService)ctx.getBean("customerCrudService");
        Customer customer = customerCrudService.findById(aLong);
        CustomerAddress customerAddress = customer.getCustomerAddress();
        return customerAddress.getStreetAddress();
    }

    @Override
    public String getCellNumber(Long aLong) {
        ctx = new ClassPathXmlApplicationContext("classpath:com/startup/musicstore/app/conf/applicationContext-*.xml");
        CustomerCrudService customerCrudService = (CustomerCrudService)ctx.getBean("customerCrudService");
        Customer customer = customerCrudService.findById(aLong);        
        Contact contact = customer.getContact();
        return contact.getContactNumber();
    }
    
}
